<template>
	<view class="ys">
		<y-header></y-header>
		<view class="login">
			<view class="pc">
				<y-bread :name="pageName"></y-bread>
			</view>
			<view class="loginbox">
				<view class="infobox">
					<view class="inputli">
						<view class="input-text">
							{{$t('index.zh')}}
						</view>
						<view class="input-body">
							<uni-icons type="person"></uni-icons>
							<input type="text" :placeholder="$t('index.qsrndzh')" v-model="username">
						</view>
					</view>
					<view class="inputli">
						<view class="input-text">
							{{$t('index.password')}}
						</view>
						<view class="input-body">
							<uni-icons type="locked"></uni-icons>
							<input type="password" :placeholder="$t('index.qsrndmm')" v-model="password">
						</view>
					</view>
					<view class="inputli forget" @click="toPage('/pages/login/forget')"
						style="text-align: right;font-size: 13px;">
						{{$t('index.wjmm')}}?
					</view>
					<view class="btn">
						<button :disabled="loading" :loading="loading" @click="login">{{$t('index.dl')}}</button>
					</view>
					<view class="tips">
						<view>
							{{$t('index.logintipsone')}}
						</view>
					</view>
					<view class="res">
						{{$t('index.myzh')}}<text @click="toPage('/pages/login/register')">{{$t('index.ljzc')}}</text>
					</view>
				</view>
			</view>
			<view class=" tsbox">
				<text class="ts">{{$t('index.tsn')}}：</text>{{$t('index.logintipstwo')}}
			</view>
		</view>
	</view>
</template>

<script>
	let flag = false
	let recaptcha = false;
	var callback = function(args) {
		recaptcha = true
		console.log('验证成功');
	};
	var expiredCallback = function(args) {
		recaptcha = false
		grecaptcha.reset()
		console.log('验证过期');
	};
	var errorCallback = function(args) {
		console.log('验证失败');
	};
	var onloadCallback = function() {
		grecaptcha.render('robot', {
			'sitekey': '6LfrVSspAAAAAL-JShr3taxXngHYbeMCqV3eki9b', //公钥
			'theme': 'light', //主题颜色，有light与dark两个值可选
			'size': 'normal', //尺寸规则，有normal与compact两个值可选
			'callback': callback, //验证成功回调
			'expired-callback': expiredCallback, //验证过期回调
			'error-callback': errorCallback //验证错误回调
		})
		console.log('初始化');
	}
	import {
		login
	} from "@/api/api.js"
	export default {
		data() {
			return {
				pageName: this.$t('index.dl'),
				loading: false,
				username: '',
				password: ''
			}
		},
		onLoad() {

		},
		methods: {
			toPage(url) {
				uni.navigateTo({
					url
				})
			},
			login() {
				let that = this
				that.loading = true
				login({
					username: that.username,
					password: that.password
				}).then(res => {
					uni.$showMsg(res.msg)
					if (res.code == 0) {
						uni.setStorageSync('jun-token', res.data.user.token)
						setTimeout(() => {
							uni.redirectTo({
								url: '/pages/user/info'
							})
						}, 500)
					} else {
						this.loading = false
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login {
		max-width: 1180px;
		margin: 0 auto;
		width: 100%;
		padding: 10px;
		box-sizing: border-box;
	}

	.loginbox {
		margin-left: auto;
		margin-right: auto;
		max-width: 610px;
		border: 1px solid #dddddd;
		padding: 30px 135px 0px;
		box-sizing: border-box;
		width: 96%;
	}

	.tsbox {
		width: 96%;
		margin-left: auto;
		margin-right: auto;
		max-width: 610px;
		border: 1px solid #dddddd;
		padding: 10px 30px;
		box-sizing: border-box;
		font-size: 14px;
		margin-top: 20px;
		color: #999999;

		.ts {
			color: #ff5353;
			line-height: 2;
		}
	}

	.res {
		text-align: center;
		font-size: 14px;
		margin-bottom: 20px;

		text {
			color: #428bca;
			cursor: pointer;
			margin-left: 2px;
		}
	}

	.btn {
		padding: 0 10px;
		margin-top: 15px;

		button {
			background: #ff5353;
			color: #fff;
			height: 40px;
			line-height: 40px;
			font-size: 14px;
		}
	}

	.tips {
		color: #606060;
		margin: 15px 0px;
		font-size: 11px;
		line-height: 16px;
		padding: 0 10px;

		view {
			padding: 10px 12px;
			background: #fffbeb;
		}
	}

	.inputli {
		padding: 10px;

		.input-text {
			font-size: 14px;
			color: #333333;
			margin-bottom: 10px;
		}

		.input-body {
			border: 1px solid #ccc;
			border-radius: 5px;
			display: flex;
			align-items: center;
			padding: 7px;
			box-sizing: border-box;

			input {
				padding-left: 5px;
				font-size: 14px;
				box-sizing: border-box;
				flex: 1;
			}
		}
	}

	@media (max-width:768px) {
		.loginbox {
			padding: 10px;
			margin-top: 30px;
		}

		.pc {
			display: none;
		}

		.tsbox {
			padding: 10px;
		}
	}
</style>